<?php

/**
 * This is the model class for table "jobs".
 *
 * The followings are the available columns in table 'jobs':
 * @property integer $id
 * @property string $for_model
 * @property integer $foreign_key
 * @property string $type
 * @property integer $handled_date
 * @property string $handled_by
 * @property integer $complete_date
 */
class jobs_delivery extends ActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return jobs the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'jobs_delivery';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('job_id, company, address', 'required'),
            array('company', 'length', 'max' => 125),
            array('address', 'length', 'max' => 512),
            array('attn', 'length', 'max' => 50),
            array('tool', 'length', 'max' => 256),
            array('job_id', 'exist', 'className' => 'job', 'attributeName' => 'id'),
            array('remark', 'safe'),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'company' => 'Company name',
            'address' => 'Delivery address',
            'attn' => 'Contact person',
            'tool' => 'Tools needed',
            'remark' => 'Remark',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);

        $criteria->compare('for_model', $this->for_model, true);

        $criteria->compare('foreign_key', $this->foreign_key);

        $criteria->compare('type', $this->type, true);

        $criteria->compare('handled_date', $this->handled_date);

        $criteria->compare('handled_by', $this->handled_by, true);

        $criteria->compare('complete_date', $this->complete_date);

        return new CActiveDataProvider(get_class($this), array(
            'criteria' => $criteria,
        ));
    }

}